//
//  HeaderCollectionViewCell.m
//  ArtWalker
//
//  Created by Mac Jc on 15/8/4.
//  Copyright (c) 2015年 Mac Jc. All rights reserved.
//

#import "HeaderCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import "AllHeader.h"
#import "UIImage+ImageBlur.h"
#import <SDImageCache.h>

@implementation HeaderCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if ( self) {
        _imageView = [[UIImageView alloc] init];
        
        _backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        _backgroundImageView.layer.cornerRadius = 4;
        _backgroundImageView.layer.masksToBounds = YES;
        [_backgroundImageView setContentMode:(UIViewContentModeScaleAspectFill)];
        _backgroundImageView.backgroundColor = kRandomColor;
        
        [self.contentView addSubview:_backgroundImageView];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_backgroundImageView.width / 2 - 28, _backgroundImageView.height /2.0 - 7, 56, 14)];
        _nameLabel.font = [UIFont systemFontOfSize:14];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.text = @"推荐";
        [self.contentView addSubview:_nameLabel];
    }
    return  self;
}

- (void)setArea:(AreaModel *)area{
    _area = area;
    if(_area.backImg){
        /**
         *  UIImageView+WebCache中的下面这个方法，可以对image进行操作
         *
         *  @param image     赋值给imageView的image
         *  @param error     发生错误的时候，错误原因
         *  @param cacheType 缓存类型
         *  @param imageURL  图片的来源
         *
         *  @return 已经赋过image值的imageView
         */
        [_backgroundImageView sd_setImageWithURL:[NSURL URLWithString:_area.backImg]  placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageLowPriority) completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            UIImage *bImage = [image boxblurImageWithBlur:0.75];
            _backgroundImageView.image = bImage;
        }];
        
    } else {
        UIImage *mImage = [UIImage imageNamed:@"NineSchoolHolder"];
        _backgroundImageView.image = [mImage boxblurImageWithBlur:0.75];
    }
      _nameLabel.text = _area.place;
}



@end
